package com.hbsx.why.ui.home;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.hbsx.why.NormalMainActivity;
import com.hbsx.why.R;
import com.hbsx.why.adapter.ActivityListAdapter;
import com.hbsx.why.adapter.LGViewHolder;
import com.hbsx.why.base.BaseActivity;
import com.hbsx.why.ui.activity.ActivityChildFragment;
import com.hbsx.why.utils.PopMenu;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by User on 2017/8/30.
 */

public class JiaoYuActivity extends BaseActivity {

    @BindView(R.id.tv_topTitle)
    TextView titleTxt;
//    @BindView(R.id.my_PullListView)
//    PullListView myPullListView;
//    @BindView(R.id.my_PullToRefreshLayout)
//    PullToRefreshLayout myPullToRefreshLayout;

    private static String mTitle;
    private static String BUNDLE_flag = "BUNDLE_flag";
    @BindView(R.id.area_text)
    TextView areaText;
    @BindView(R.id.space_text)
    TextView spaceText;
    @BindView(R.id.time_text)
    TextView timeText;
    @BindView(R.id.type_text)
    TextView typeText;
    private int flag;
    public static NormalMainActivity myNormalMainActivity;
    private List<String> stringList, flagString;
    private int page = 0;
    private ActivityListAdapter listAdapter;
    private Context context = this;
    private PopMenu<String> popMenu;

    @Override
    protected int getLayoutResId() {
        return R.layout.jiaoyu_main;
    }

    @Override
    protected void initView() {
        titleTxt.setText(getIntent().getStringExtra("title"));
        Bundle arguments = new Bundle();
        if (arguments != null) {
            flag = arguments.getInt(BUNDLE_flag);
        }
        stringList = new ArrayList<>();
        listAdapter = new ActivityListAdapter(context, stringList);
    }

    private void getData(int page) {
    }

    public static ActivityChildFragment newInstance() {
        ActivityChildFragment fragment = new ActivityChildFragment();
        return fragment;
    }

    public static ActivityChildFragment newInstance(String title, int flag) {
        ActivityChildFragment fragment = new ActivityChildFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(BUNDLE_flag, flag);
        mTitle = title;
        fragment.setArguments(bundle);
        return fragment;
    }

    @OnClick({R.id.area_text, R.id.area_img, R.id.space_text, R.id.space_img, R.id.time_text, R.id.time_img, R.id.type_text, R.id.type_img})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.area_text:
                initPop(areaText, 1);
                break;
            case R.id.area_img:
                initPop(areaText, 1);
                break;
            case R.id.space_text:
                initPop(spaceText, 2);
                break;
            case R.id.space_img:
                initPop(spaceText, 2);
                break;
            case R.id.time_text:
                initPop(timeText, 3);
                break;
            case R.id.time_img:
                initPop(timeText, 3);
                break;
            case R.id.type_text:
                initPop(typeText, 4);
                break;
            case R.id.type_img:
                initPop(typeText, 4);
                break;
        }
    }

    private void initPop(final TextView textView, final int flag) {
        if (flag == 1) {
            flagString = new ArrayList<>();
            for (int i = 0; i < 7; i++) {
                if (i == 0) {
                    flagString.add("市辖区");
                }
                if (i == 1) {
                    flagString.add("瑶海区");
                }
                if (i == 2) {
                    flagString.add("庐阳区");
                }
                if (i == 3) {
                    flagString.add("包河区");
                }
                if (i == 4) {
                    flagString.add("蜀山区");
                }
                if (i == 5) {
                    flagString.add("肥东县");
                }
                if (i == 6) {
                    flagString.add("长丰县");
                }
            }
        }
        if (flag == 2) {
            flagString = new ArrayList<>();
            for (int i = 0; i < 7; i++) {
                if (i == 0) {
                    flagString.add("安徽省图书馆");
                }
                if (i == 1) {
                    flagString.add("安徽省文化馆");
                }
                if (i == 2) {
                    flagString.add("安徽省博物馆");
                }
                if (i == 3) {
                    flagString.add("合肥市图书馆");
                }
                if (i == 4) {
                    flagString.add("合肥市文化馆");
                }
                if (i == 5) {
                    flagString.add("合肥市美术馆");
                }
                if (i == 6) {
                    flagString.add("安徽省体育馆");
                }
            }
        }
        if (flag == 3) {
            flagString = new ArrayList<>();
            for (int i = 0; i < 2; i++) {
                if (i == 0) {
                    flagString.add("往期活动");
                }
                if (i == 1) {
                    flagString.add("近期活动");
                }
            }
        }
        if (flag == 4) {
            flagString = new ArrayList<>();
            for (int i = 0; i < 2; i++) {
                if (i == 0) {
                    flagString.add("预约");
                }
                if (i == 1) {
                    flagString.add("免预约");
                }

            }
        }
        popMenu = new PopMenu<String>(context, flagString) {
            @Override
            public int getLayoutManu() {
                return R.layout.layout_pomenu;
            }

            @Override
            protected int getmLayoutId() {
                return R.layout.item_pomenu;
            }

            @Override
            protected void binderconvert(LGViewHolder holder, final String s, int position) {
                TextView textview = (TextView) holder.getView(R.id.popwin_textView);
                textview.setText(s);
                textview.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        textView.setText(s);
                        popMenu.dismiss();
                    }
                });
            }
        };
        popMenu.showAsDropDown(textView);
    }
}
